package com.zl.springcloudfeignserver;

import feign.hystrix.FallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: ZhangLiang
 * @Date: 2021/08/23/22:15
 * @Description:
 */
@FeignClient(value = "eureka-client", fallbackFactory = EurekaClientFallbackFactory.EurekaClientFallbackFactoryImpl.class)
public interface EurekaClientFallbackFactory {

    @GetMapping(value = "/hi")
    String sayHiFromClientOne(@RequestParam(value = "name") String name);


    @Component
    static class EurekaClientFallbackFactoryImpl implements FallbackFactory<EurekaClientFallbackFactory> {
        @Override
        public EurekaClientFallbackFactory create(Throwable cause) {
            return new EurekaClientFallbackFactory() {
                @Override
                public String sayHiFromClientOne(String name) {
                    return "fallback; reason was: " + cause.getMessage();
                }
            };
        }
    }
}

